package com.carlinfo.controller.head;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.carlinfo.common.controller.BaseController;
import com.carlinfo.common.util.ConstantFinalUtil;
import com.carlinfo.common.util.PageInfoUtil;
import com.carlinfo.users.pojo.ACourse;
import com.carlinfo.users.pojo.ANews;
import com.carlinfo.users.pojo.APartner;
import com.carlinfo.users.pojo.AQqInfo;
import com.carlinfo.users.pojo.ATeachers;
import com.carlinfo.users.service.ICateService;
import com.carlinfo.users.service.ICourseService;
import com.carlinfo.users.service.INewsService;
import com.carlinfo.users.service.IPartnerService;
import com.carlinfo.users.service.IQqInfoService;
import com.carlinfo.users.service.ITeachersService;

/**
 * 不需要登录直接就可以访问的页面
 * 
 * @author Gonsen
 *
 */
@Controller
public class IndexHeadController extends BaseController {
	@Resource
	private INewsService newsService;
	@Resource
	private ICateService cateService;
	@Resource
	private ITeachersService teachersService;
	@Resource
	private ICourseService courseService;
	@Resource
	private IPartnerService partnerService;
	@Resource
	private IQqInfoService qqInfoService;
	/**
	 * 首页
	 * @return /head/main
	 */
	@RequestMapping(value = {"","/","index.htm"})
	public String main(Model model,HttpServletRequest request) {
		ConstantFinalUtil.LOGGER.info("===main==");
		PageInfoUtil pageInfoUtil = new PageInfoUtil();
		Map<String,Object> condMap = new HashMap<>();
		condMap.put("result", "index_show");
 		List<ACourse> courseList = courseService.findCondProdList(pageInfoUtil, condMap);
 		model.addAttribute("courseList", courseList);
 		condMap.clear();
 		List<APartner> partnerList = partnerService.findCondPartnerList(pageInfoUtil, condMap);
 		model.addAttribute("partnerList", partnerList);
 		condMap.put("status", 1);
 		AQqInfo qqInfo = qqInfoService.findOneQqInfoService(condMap);
		request.getSession().setAttribute("QQ", qqInfo.getQQ());
		return "/head/main";
	}

	/**
	 * 新闻页面
	 * @param model
	 * @return /head/newsList
	 */
	@RequestMapping("/news")
	public String news(Model model) {
		ConstantFinalUtil.LOGGER.info("===news==");
		PageInfoUtil pageInfoUtil = new PageInfoUtil();
		Map<String, Object> condMap = new HashMap<String, Object>();
		/**
		 * 查询数据库
		 */
		List<ANews> newsList = this.newsService.findCondNewsList(pageInfoUtil, condMap);
		model.addAttribute("newsList", newsList);
		return "/head/newsList";
	}

	/**
	 * 新闻页面详情页
	 * @return
	 */
	@RequestMapping("/newsinfo")
	public String newsList(Model model, @RequestParam(value = "newsID", required = true) int id) {
		ConstantFinalUtil.LOGGER.info("===news_info_1==");
		Map<String, Object> condMap = new HashMap<String, Object>();
		/**
		 * 查询数据库
		 */
		// List<ACate> cateList = this.cateService.findCondCateList(pageInfoUtil,
		// condMap);
//		condMap.put("newsID", id);
//		ACate aCate = this.cateService.findOneCateService(condMap);
		// model.addAttribute("cateList", cateList);
//		model.addAttribute("aCate", aCate);
		condMap.put("id", id);
		ANews news = newsService.findOneNewsService(condMap);
		model.addAttribute("news", news);
		return "/head/newsinfo";
	}

	/**
	 * 教育产品页面
	 * @param model
	 * @param sub
	 * @return "/head/edu_" + sub
	 */
	@RequestMapping("edu_{sub}")
	public String edu_tea(Model model, @PathVariable String sub) {
		ConstantFinalUtil.LOGGER.info("===" + sub + "==");
		PageInfoUtil pageInfoUtil = null;
		Map<String, Object> condMap = new HashMap<String, Object>();
		/**
		 * 查询数据库
		 */
		if (sub.equals("tea")) {
			List<ATeachers> teachersList = this.teachersService.findCondTeachersList(pageInfoUtil, condMap);
			model.addAttribute("teachersList", teachersList);
		} else if (sub.equals("job")) {

		} else if (sub.equals("jiuyi")) {
			condMap.put("groupName", "jiuyi");
			List<ACourse> courseList = courseService.findCondProdList(pageInfoUtil, condMap);
			model.addAttribute("courseList", courseList);
		} else if (sub.equals("chiyi")) {
			condMap.put("groupName", "chiyi");
			List<ACourse> courseList = courseService.findCondProdList(pageInfoUtil, condMap);
			model.addAttribute("courseList", courseList);
		}
		return "/head/edu_" + sub;
	}
	
	/**
	 * 
	 * @param u3d
	 * @return /head/u3d
	 */
	@RequestMapping("u3d")
	public String u3d() {
		ConstantFinalUtil.LOGGER.info("===u3d==");
		return "/head/u3d";
	}
	
	/**
	 * 
	 * @param android
	 * @return /head/android
	 */
	@RequestMapping("android")
	public String android() {
		ConstantFinalUtil.LOGGER.info("===android===");
		return "/head/android";
	}
	
	/**
	 * 
	 * @param iosInfo
	 * @return /head/iosInfo
	 */
	
	@RequestMapping("iosInfo")
	public String iosInfo() {
		ConstantFinalUtil.LOGGER.info("===iosInfo===");
		return "/head/iosInfo";
	}
	
	/**
	 * 
	 * @param uedInfo
	 * @return /head/uedInfo
	 */
	@RequestMapping("uedInfo")
	public String uedInfo() {
		ConstantFinalUtil.LOGGER.info("===uedInfo===");
		return "/head/uedInfo";
	}

	/**
	 * 
	 * @param productManager
	 * @return /head/productManager
	 */
	@RequestMapping("productManager")
	public String productManager() {
		ConstantFinalUtil.LOGGER.info("===productManager===");
		return "/head/productManager";
	}
	
	/**
	 * 关于页面
	 * @param model
	 * @return /head/about
	 */
	@RequestMapping("about")
	public String about(Model model) {
		ConstantFinalUtil.LOGGER.info("===about===");
		
		return "/head/about";
	}

	/**
	 * 创新产品页面
	 * @param model
	 * @param sub
	 * @return "/head/prod_" + sub
	 */
	@RequestMapping("prod_{sub}")
	public String prod_share(Model model, @PathVariable String sub) {
		ConstantFinalUtil.LOGGER.info("===" + sub + "===");
		if (sub.equals("share")) {
			
		} else if (sub.equals("tour")) {

		} else if (sub.equals("ai")) {

		} else if (sub.equals("exp")) {

		}
		return "/head/prod_" + sub;
	}

	/**
	 * 
	 * @param highEfficiency
	 * @return /head/highEfficiency
	 */
	@RequestMapping("highEfficiency")
	public String highEfficiency() {
		ConstantFinalUtil.LOGGER.info("===highEfficiency===");
		return "/head/highEfficiency";
	}
	/**
	 * 
	 * @param comfortable
	 * @return /head/comfortable
	 */
	@RequestMapping("comfortable")
	public String comfortable() {
		ConstantFinalUtil.LOGGER.info("===comfortable===");
		return "/head/comfortable";
	}
	/**
	 * 
	 * @param care
	 * @return /head/care
	 */
	@RequestMapping("care")
	public String care() {
		ConstantFinalUtil.LOGGER.info("===care===");
		return "/head/care";
	}
	
	/**
	 * 
	 * @param pythonInfo
	 * @return /head/pythonInfo
	 */
	@RequestMapping("pythonInfo")
	public String pythonInfo() {
		ConstantFinalUtil.LOGGER.info("===pythonInfo===");
		return "/head/course";
	}
	
	/**
	 * 
	 * @param bigData
	 * @return /head/bigData
	 */
	@RequestMapping("bigDataInfo")
	public String bigData() {
		ConstantFinalUtil .LOGGER.info("===bigData===");
		return "/head/course";
	}
	
	/**
	 * 
	 * @param html5Info
	 * @return /head/html5Info
	 */
	@RequestMapping("html5Info")
	public String html5() {
		ConstantFinalUtil.LOGGER.info("===html5Info===");
		return "/head/course";
	}
	
	/**
	 * 
	 * @return /head/javaEE_enterpriseInfo
	 */
	@RequestMapping("course")
	public String javaEE_enterpriseInfo(Model model,@RequestParam int id) {
		ConstantFinalUtil.LOGGER.info("==="+id+"===");
		Map<String,Object> condMap = new HashMap<>();
		condMap.put("result", "content");
		condMap.put("id", id);
 		ACourse course = courseService.findOneProdService(condMap);
 		model.addAttribute("course", course);
		return "/head/course";
	}
	
	/**
	 * 
	 * @return /head/prod_share_info_1
	 */
	@RequestMapping("prod_share_info_1")
	public String prod_share_info_1() {
		ConstantFinalUtil.LOGGER.info("===prod_share_info_1===");
		return "/head/prod_share_info_1";
	}
	
	/**
	 * 
	 * @return /head/prod_exp_info_1
	 */
	@RequestMapping("prod_exp_info_1")
	public String prod_exp_info_1() {
		ConstantFinalUtil.LOGGER.info("====prod_exp_info_1===");
		return "/head/prod_exp_info_1";
	}
	
	/**
	 * 联系我们页面
	 * @param model
	 * @return /head/contact
	 */
	@RequestMapping("contact")
	public String contact(Model model) {
		ConstantFinalUtil.LOGGER.info("===contact==");
		return "/head/contact";
	}

}
